package org.example.hadoop.service.publisherSort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.example.hadoop.domain.AuthorCountBean;
import org.example.hadoop.domain.PublisherCountBean;

import java.io.IOException;

/**
 * @Author: wwy
 * @Date: 2020/11/10 16:49
 */
public class PublisherSortMapper extends Mapper<LongWritable, Text, PublisherCountBean, Text> {
    /**
     * k1     v1
     *        余华 4
     * k2                   v2
     *
     * AuthorCountBean      余华,aa,bbb,ccc,ddd
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] valueArray = line.split("\t");
        String publisherName = valueArray[0];
        int count = Integer.parseInt(valueArray[1]);
        PublisherCountBean publisherCountBean = new PublisherCountBean();
        publisherCountBean.setCount(count);
        context.write(publisherCountBean,new Text(publisherName));
    }
}
